package com.www.applyword.ui.home;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.www.applyword.Constants.Constants;
import com.www.applyword.R;
import com.www.applyword.adapter.GirdDropDownAdpter3;
import com.www.applyword.adapter.JobWorkAdapter2;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.bean.LoginBean;
import com.www.applyword.bean.WXPayBean;
import com.www.applyword.http.CallBack;
import com.www.applyword.http.HttpClient;
import com.www.applyword.main.MainActivity;
import com.www.applyword.ui.my.MyEnterpriseActivity;
import com.www.applyword.ui.my.MyReSumeActivity;
import com.www.applyword.ui.my.MyRealNameActivity;
import com.www.applyword.utils.SPUtil;
import com.www.applyword.utils.Utils;
import com.www.applyword.view.MyGridView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * author : huang
 * date   : 2019/10/23 0023 14:00
 * version: 1.0
 *
 * @author Administrator
 */
public class HomeSignInActivity extends BaseActivity {
    @BindView(R.id.ll_sign_in)
    LinearLayout llSignIn;
    @BindView(R.id.tv_sign)
    TextView tv_sign;
    @BindView(R.id.tv_fen)
    TextView tv_fen;
    @BindView(R.id.tv_jin)
    TextView tv_jin;
    @BindView(R.id.gv)
    MyGridView gv;
    @BindView(R.id.iv_sign)
    ImageView ivSign;
    @BindView(R.id.ll_fabu)
    LinearLayout llFabu;
    @BindView(R.id.ll_hot)
    LinearLayout llHot;
    @BindView(R.id.ll_new)
    LinearLayout llNew;
    @BindView(R.id.st_apply)
    LinearLayout stApply;
    @BindView(R.id.tv10)
    TextView tv10;
    @BindView(R.id.tv_3)
    TextView tv_3;
    @BindView(R.id.sb1)
    SuperButton sb1;
    @BindView(R.id.iv1)
    ImageView iv1;
    @BindView(R.id.sb2)
    SuperButton sb2;
    @BindView(R.id.iv2)
    ImageView iv2;
    @BindView(R.id.sb3)
    SuperButton sb3;
    @BindView(R.id.iv3)
    ImageView iv3;
    @BindView(R.id.sb4)
    SuperButton sb4;
    @BindView(R.id.iv4)
    ImageView iv4;
    @BindView(R.id.sb5)
    SuperButton sb5;
    @BindView(R.id.iv5)
    ImageView iv5;
    private JobWorkAdapter2 mJobWorkAdapter;
    private GirdDropDownAdpter3 cityAdapter;
    public boolean flag;


    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.home_sign_activity);
        setTitle("签到任务");

    }

    @Override
    protected void loadData() {
        // getUserSignInfo();
        List<String> date = Utils.get7date();

        cityAdapter = new GirdDropDownAdpter3(this, date);
        gv.setAdapter(cityAdapter);

        //  mJobWorkAdapter.replaceAll(date, true);
        Map<String, Object> params = new HashMap<>();
        params.put("userId", SPUtil.getString(Constants.USERID));
        HttpClient.get(HomeSignInActivity.this, Constants.GETUSERSIGNINFO, params, new CallBack<WXPayBean>() {
            @Override
            public void onSuccess(WXPayBean wxPayBean) {
                tv_fen.setText(wxPayBean.Integer + "");
                if (wxPayBean.Integer <= 100){
                    tv_3.setText("我的等级：1级");
                }else if (wxPayBean.Integer <= 200){
                    tv_3.setText("我的等级：2级");
                }else {
                    tv_3.setText("我的等级：3级");
                }
                SPUtil.put(Constants.JIFFEN, wxPayBean.Integer);
                if (wxPayBean.TodaySign == 1) {   // 1 表示已签到
                    tv_sign.setText("已签到");
                    tv_jin.setVisibility(View.GONE);
                    flag = true;
                    cityAdapter.notifyDataSetChanged();
                }else {
                     flag = false;
                }
                if (wxPayBean.SignUp != 0) { //不为0是已提交  报名兼职
                    iv2.setVisibility(View.VISIBLE);
                    sb2.setVisibility(View.GONE);
                }
              if (wxPayBean.RealName == 2) { //已认证
                  iv3.setVisibility(View.VISIBLE);
                  sb3.setVisibility(View.GONE);
              }
               if (wxPayBean.EnterpriseCertification == 1) { //成功
                   iv4.setVisibility(View.VISIBLE);
                   sb4.setVisibility(View.GONE);
               }
                if (wxPayBean.ResumeBasic != 0) { //1 表示已填写
                    iv5.setVisibility(View.VISIBLE);
                    sb5.setVisibility(View.GONE);
                }
               if (wxPayBean.Order != 0){   //发布招聘
                    iv1.setVisibility(View.VISIBLE);
                    sb1.setVisibility(View.GONE);
                }
            }
        });
    }


    @OnClick(R.id.ll_sign_in)
    public void onViewClicked() {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", SPUtil.getString(Constants.USERID));
        HttpClient.get(HomeSignInActivity.this, Constants.SIGNINFO, params, new CallBack<LoginBean>() {
            @SuppressLint("ResourceAsColor")
            @Override
            public void onSuccess(LoginBean result) {
                tv_sign.setText("已签到");
                flag = true;
                tv_sign.setTextColor(R.color.text_color2);
                tv_jin.setVisibility(View.GONE);
                cityAdapter.notifyDataSetChanged();
                getMyInfo();
            }
        });
    }

    private void getMyInfo() {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", SPUtil.getString(Constants.USERID));
        HttpClient.get(this, Constants.GETUSERINFO, params, new CallBack<LoginBean>() {
            @Override
            public void onSuccess(LoginBean result) {
                SPUtil.put(Constants.NAME, result.getUser().getUserInfo_NickName());
                SPUtil.put(Constants.PHOTO, result.getUser().getUserInfo_HeadImg());
                SPUtil.put(Constants.JIFFEN, result.getUser().getUserInfo_Integer());
                tv_fen.setText(result.getUser().getUserInfo_Integer() + "");
            }
        });
    }


    @OnClick({R.id.ll_fabu, R.id.ll_hot, R.id.ll_new, R.id.sb1, R.id.sb2, R.id.sb3, R.id.sb4, R.id.sb5})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_fabu:
                Utils.startActivity(MyGoodListActivity.class);
                break;
            case R.id.ll_hot:
                Utils.startActivity(MyFenActivity.class);
                break;
            case R.id.ll_new:
                Utils.startActivity(ExchangeActivity.class);
                break;
            case R.id.sb1:
               int userInfo_state =  getIntent().getIntExtra("userInfo_state", 0);
                if (userInfo_state == 0){
                    Utils.showToastSafe("请先实名认证");
                    Utils.startActivity(MyRealNameActivity.class);
                    return;
                }
                if (userInfo_state == -1){
                    Utils.showToastSafe("您的实名认证正在审核中");
                    return;
                }
                Utils.startActivity(PostJobActivity.class);
                break;
            case R.id.sb2:
                Utils.startActivity(MainActivity.class);
                break;
            case R.id.sb3:
                Utils.startActivity(MyRealNameActivity.class);
                break;
            case R.id.sb4:
                Utils.startActivity(MyEnterpriseActivity.class);
                break;
            case R.id.sb5:
                Utils.startActivity(MyReSumeActivity.class);
                break;
            default:
        }
    }


}
